package com.property.manage.controller.equipment;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.equipment.EquipmentVo;
import com.property.manage.service.equipment.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "设备管理")
@RestController
@RequestMapping("/equipment")
@AllArgsConstructor
@Validated
public class EquipmentController {
    @Autowired
    private EquipmentService equipmentService;


    @ApiOperation("设备列表")
    @GetMapping("/page")
    public CustomPage<EquipmentVo> userPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                            @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                            @ApiParam("小区id") @RequestParam(value = "quarterId", required = false) Integer quarterId,
                                            @ApiParam("设备名称") @RequestParam(value = "name", required = false) String name){
        return equipmentService.page(pageNo,pageSize,quarterId,name);
    }

    @ApiOperation("保养到期的设备列表")
    @GetMapping("/getRepairPage")
    public CustomPage<EquipmentVo> getRepairPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                            @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                            @ApiParam("小区id") @RequestParam(value = "quarterId", required = false) Integer quarterId){
        return equipmentService.getRepairPage(pageNo,pageSize,quarterId);
    }

    @ApiOperation("设备保养与维修到期统计表")
    @GetMapping("/getRepairCount")
    public Integer getRepairCount(@ApiParam("小区id") @RequestParam(value = "quarterId", required = false) Integer quarterId){
        return equipmentService.getRepairCount(quarterId);
    }


    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@ApiParam("小区id")@RequestParam(value = "villageId")@NotNull(message = "小区id不能为空") Integer villageId,
                    @ApiParam("设备名称")@RequestParam(value = "name")@NotBlank(message = "设备名称") String name,
                    @ApiParam("设备编号") @RequestParam(value = "number")@NotBlank(message = "设备编号不能为空") String number,
                    @ApiParam("设备生产日期")@RequestParam(value = "dateManufacture",required = false) String dateManufacture,
                    @ApiParam("下次保养或维修时间")@RequestParam(value = "nextTime",required = false) String nextTime,
                    @ApiParam("投入使用日期")@RequestParam(value = "dateUse")@NotBlank(message = "投入使用日期不能为空") String dateUse,
                    @ApiParam("地址")@RequestParam(value = "address")@NotBlank(message = "地址不能为空") String address


    ){
        equipmentService.add(name,number,dateManufacture,villageId,dateUse,nextTime,address);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @ApiParam("设备名称")@RequestParam(value = "name")@NotBlank(message = "设备名称") String name,
                       @ApiParam("设备编号") @RequestParam(value = "number")@NotBlank(message = "设备编号不能为空") String number,
                       @ApiParam("设备生产日期")@RequestParam(value = "dateManufacture",required = false) String dateManufacture,
                       @ApiParam("下次保养或维修时间")@RequestParam(value = "nextTime",required = false) String nextTime,
                       @ApiParam("投入使用日期")@RequestParam(value = "dateUse")@NotBlank(message = "投入使用日期不能为空") String dateUse,
                       @ApiParam("地址")@RequestParam(value = "address")@NotBlank(message = "地址不能为空") String address
    ){
       equipmentService.update(id,name,number,dateManufacture,dateUse,nextTime,address);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("id") @RequestParam("id") @NotNull(message = "id为空") Integer id){
        equipmentService.delete(id);
    }


}
